home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / diffs / make-3.71 / function.c < prev    next >
Encoding:
Text File  |  1994-08-05  |  2.8 KB  |  113 lines

  1. *** orig/make-3.71/function.c    Thu Jul 21 01:30:00 1994
  2. --- src/make-3.71/function.c    Thu Jul 21 02:03:30 1994
  3. ***************
  4. *** 22,27 ****
  5. --- 22,31 ----
  6.   #include "commands.h"
  7.   #include "job.h"
  8.   
  9. + #ifdef __MSDOS__
  10. + #include <process.h>
  11. + #endif
  12.   static char *string_glob ();
  13.   
  14.   /* Store into VARIABLE_BUFFER at O the result of scanning TEXT and replacing
  15. ***************
  16. *** 326,332 ****
  17.     int doneany = 0;
  18.     int count;
  19.     char endparen = *end, startparen = *end == ')' ? '(' : '{';
  20.     switch (function)
  21.       {
  22.       default:
  23. --- 330,336 ----
  24.     int doneany = 0;
  25.     int count;
  26.     char endparen = *end, startparen = *end == ')' ? '(' : '{';
  27. !   
  28.     switch (function)
  29.       {
  30.       default:
  31. ***************
  32. *** 371,376 ****
  33. --- 375,381 ----
  34.       else
  35.         error_prefix = "";
  36.   
  37. + #ifndef __MSDOS__
  38.       if (pipe (pipedes) < 0)
  39.         {
  40.           perror_with_name (error_prefix, "pipe");
  41. ***************
  42. *** 475,480 ****
  43. --- 480,546 ----
  44.   
  45.           free (buffer);
  46.         }
  47. + #else /* __MSDOS__ */
  48. +         {
  49. +       /* MS-DOS can't do fork, but it can do spawn.  However, this means
  50. +          that we don't have an opportunity to reopen stdout to trap it.
  51. +          Thus, we save our own stdout onto a new descriptor and dup a
  52. +          temp file's descriptor onto our stdout temporarily.  After we
  53. +          spawn the shell program, we dup our own stdout back to the
  54. +          stdout descriptor.  The buffer reading is the same as above,
  55. +          except that we're now reading from a file. */
  56. +       
  57. +       int save_stdout;
  58. +       int child_stdout;
  59. +       char tmp_output[FILENAME_MAX];
  60. +       FILE *child_stream;
  61. +       int maxlen = 200, cc;
  62. +       char *buffer;
  63. +       strcpy(tmp_output, "shXXXXXX");
  64. +       mktemp(tmp_output);
  65. +       child_stdout = open(tmp_output, O_WRONLY|O_CREAT|O_TRUNC|O_TEXT, 0644);
  66. +       save_stdout = dup(1);
  67. +       dup2(child_stdout, 1);
  68. +       spawnvp(P_WAIT, argv[0], argv);
  69. +       dup2(save_stdout, 1);
  70. +       close(child_stdout);
  71. +       close(save_stdout);
  72. +       child_stdout = open(tmp_output, O_RDONLY|O_TEXT, 0644);
  73. +       buffer = xmalloc(maxlen);
  74. +       i = 0;
  75. +       do
  76. +       {
  77. +         if (i == maxlen)
  78. +         {
  79. +           maxlen += 512;
  80. +           buffer = (char *) xrealloc (buffer, maxlen + 1);
  81. +         }
  82. +         cc = read (child_stdout, buffer+i, maxlen - i);
  83. +         if (cc > 0)
  84. +           i += cc;
  85. +       } while (cc > 0);
  86. +       close(child_stdout);
  87. +       unlink(tmp_output);
  88. +       if (i > 0)
  89. +       {
  90. +         if (buffer[i - 1] == '\n')
  91. +           buffer[--i] = '\0';
  92. +         else
  93. +           buffer[i] = '\0';
  94. +         p = buffer;
  95. +         while ((p = index (p, '\n')) != 0)
  96. +           *p++ = ' ';
  97. +         o = variable_buffer_output (o, buffer, i);
  98. +       }
  99. +       free(buffer);
  100. +     }
  101. + #endif /* ?__MSDOS__ */
  102.   
  103.       free (text);
  104.       break;
  105.